<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell @click="cellClickFn">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ item.title }}</span>
          <img
            class="thumb"
            :src="item.cover.images[0]"
            v-if="item.cover.type === 1"
          />
        </div>
        <div class="thumb-box" v-if="item.cover.type > 1">
          <img
            v-for="(imgstr, index) in item.cover.images"
            :key="index"
            class="thumb"
            :src="imgstr"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>作者 {{ item.aut_name }}&nbsp;&nbsp;</span>
            <span>{{ item.comm_count }}评论&nbsp;&nbsp;</span>
            <span>{{ item.pubdate }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click="crossFn"  v-if="closeShow"/>
        </div>
      </template>
    </van-cell>
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      get-container="body"
      :cancel-text="cancelText"
      @cancel = "cancelFn"
    />
  </div>
</template>

<script>
import { firstActions, secondActions } from '@/api/report'
export default {
  data () {
    return {
      show: false,
      actions: firstActions,
      cancelText: '取消'
    }
  },
  props: {
    item: {
      type: Object
    },
    closeShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    onSelect (action, index) {
      // this.cancelText = '返回'
      if (action.name === '反馈垃圾内容') {
        this.actions = secondActions
      } else if (action.name === '返回') {
        this.actions = firstActions
        setTimeout(() => {
          this.show = true
        })
      } else if (action.name === '不感兴趣') {
        console.log(this.item)
        this.$emit('removeE', this.item, action)
        this.show = false
      } else if (action.name === '拉黑作者') {

      } else {
        this.$emit('removeE', this.item, action)
      }
    },
    crossFn () {
      this.show = true
    },
    cancelFn () {
      // this.cancelText = '取消'
      this.actions = firstActions
    },
    // 跳转文章详情
    cellClickFn () {
      this.$router.push({
        path: `/article?aid=${this.item.art_id}`
      })
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.thumb-box {
  display: flex;
  justify-content: space-between;
}
/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
